package backend;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.jms.*;

@Component(value = "jmsListener")
public class JmsListener implements MessageListener {
    @Autowired
    private JmsTemplate jmsTemplate;

    //收到信息时的动作
    @Override
    public void onMessage(Message m)  {
        try {
            ObjectMessage message = (ObjectMessage) m;
            final String uuid=message.getObject().toString().replace("\"","");
            jmsTemplate.send("fallback", new MessageCreator() {

                public Message createMessage(Session session) throws JMSException {
                    return session.createObjectMessage(JSON.toJSONString(uuid+"_你好这是BBF的请求"));
                }
            });
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}

